<?php
class Sns_Wx{
	public $newstpl=<<<eof
<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>10</ArticleCount>
<Articles>
%s
</Articles>
</xml> 
eof;

	public $newitemtpl=<<<eof
	<item>
	<Title><![CDATA[%s]]></Title> 
	<Description><![CDATA[%s]]></Description>
	<PicUrl><![CDATA[%s]]></PicUrl>
	<Url><![CDATA[%s]]></Url>
	</item>
eof;
	function __construct($kw){
		$this->kw=$kw;
	}


	function send_msg($from,$to){
		Funs_Base::cdlog($from);
		call_user_func_array(array(self,"_{$this->kw}"), array($from,$to));
	}


	function _qb($from,$to){
		Funs_Base::cdlog($from);
		$url="http://www.qiushibaike.com/hot";
		$rs=Funs_Base::http($url);
		#echo ($rs);
		$list_pat="/<div.+?id=[\'\"]qiushi_tag.+?>(.+?)<div\s+id=[\"\']qiushi_counts/is";
		$content_pat="/<div\s+class=[\'\"]content.+?>(.+?)<\/div/is";
		$thumb_pat="/<div\s+class=[\'\"]thumb.+?img\s+src=[\'\"](.+?)[\'\"]/is";
		preg_match_all($list_pat, $rs,$match);

		$i=0;
		$items="";
		foreach($match[1] as $v){
			if($i==10) break;
			preg_match($content_pat,$v,$title_arr);
			preg_match($thumb_pat, $v,$thumb_arr);
			$picurl=empty($thumb_arr)?"":$thumb_arr[1];
			$items.=sprintf($this->newitemtpl,"",$title_arr[1],$picurl,$url);
			$i++;
		}
		#echo $items;
		$res=sprintf($this->newstpl,$to,$from,time(),$items);
		Funs_Base::cdlog($res);
		echo $res;
	}

	function _wt($from,$to){

	}


}

?>